package com.jie.commonlib.support.sputils;

import com.blankj.utilcode.util.SPUtils;

/**
 * @author jie
 */
public class UserInfoUtils {

    private static UserInfoUtils instance;
    private final SPUtils spUtils;

    private UserInfoUtils(){
        spUtils = SPUtils.getInstance(SpConstant.SP_USER_INFO);
    }

    public static UserInfoUtils getInstance() {
        if (instance == null){
            synchronized (UserInfoUtils.class){
                if (instance == null){
                    instance = new UserInfoUtils();
                }
            }
        }
        return instance;
    }

    public void putUserName(String userName){
        spUtils.put(SpConstant.User.USER_NAME, userName);
    }

    public void putPassword(String password){
        spUtils.put(SpConstant.User.PASSWORD, password);
    }

    public void putAccessToken(String accessToken){
        spUtils.put(SpConstant.User.ACCESS_TOKEN, accessToken);
    }

    public String getUserName(){
        return spUtils.getString(SpConstant.User.USER_NAME);
    }

    public String getPassword(){
        return spUtils.getString(SpConstant.User.PASSWORD);
    }

    public String getAccessToken(){
        return spUtils.getString(SpConstant.User.ACCESS_TOKEN);
    }

    /**
     * 推出登录，情况缓存用户信息
     */
    public void logout(){
        putUserName("");
        putPassword("");
        putAccessToken("");
    }
}
